<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome'}">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <el-row>
        <el-col :span="10">
          <el-input placeholder="请输入内容" v-model="value" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table style="margin: 15px 0;" :data="orders" border stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="{ row }">
            <el-tag v-if="row.pay_status === '0'" type="danger">未支付</el-tag>
            <el-tag v-else>已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="{ row }">
            {{ row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button @click="editAddressDialog = true" icon="el-icon-edit" type="primary" size="mini"></el-button>
            <el-button @click="showExpressDialog" icon="el-icon-location" type="warning" size="mini"></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 修改收获地址对话框 -->
    <el-dialog
      title="修改\地址"
      :visible.sync="editAddressDialog"
      width="50%">
      <!-- 城市三级联动 -->
      <el-cascader
      v-model="cascaderValue"
      :options="cityData"
      @change="handleChange">
      </el-cascader>
      <!-- 城市三级联动 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流信息对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="expressDialog"
      width="50%">
      <!-- 物流进度效果 -->
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(item, index) in expressList"
          :key="index"
          :timestamp="item.time">
          {{item.content}}
        </el-timeline-item>
      </el-timeline>
      <!-- /物流进度效果 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="expressDialog = false">取 消</el-button>
        <el-button type="primary" @click="expressDialog = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 导入城市数据
import cityData from './citydata.js'
export default {
  data () {
    return {
      value: '',
      queryData: {
        pagenum: 1,
        pagesize: 10
      },
      orders: [], // 存贮订单列表数据
      editAddressDialog: false,
      cascaderValue: [],
      cityData,
      expressDialog: false,
      expressList: []
    }
  },
  methods: {
    // 获取订单列表
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.orders = res.data.goods
    },
    handleChange () { },
    // 点击显示物流进度
    async showExpressDialog () {
      this.expressDialog = true
      // 获取物流进度数据
      const { data: res } = await this.$http.get('http://localhost:8082/api/express')
      this.expressList = res.data
      // console.log('获取物流数据')
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  async created () {
    this.getOrderList()
    // 脚手架 默认 开启了本地服务 http://localhost:8080/
    // 脚手架 只托管了我们写的网页
    // http://localhost:8080/api/person 肯定 404
    const res = await this.$http.get('http://localhost:8082/api/person')
    const res2 = await this.$http.get('http://localhost:8082/get/person')
    console.log(res)
    console.log(res2)
  },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
